//
//  CustomView.m
//  MasonryDemo
//
//  Created by Teplot_01 on 16/6/21.
//  Copyright © 2016年 Teplot_01. All rights reserved.
//

#import "CustomView.h"
@implementation CustomView
{
    UILabel *ageDriveLb;
    UITextField *ageDriverTF;
    UILabel *carMessLb;
    UITextField *carbrandTF;
    UITextField *carNameTF;
    UITextField *seatNumTF;
    UILabel *zuoLb;
    UILabel *huodongLb;
    UITextField *huodongTF;
    UILabel *priceLb;
    UITextField *priceTF;
    UITextView *messageTV;
}
//在initWithFrame:方法中添加子控件
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        // 注意：该处不要给子控件设置frame与数据，可以在这里初始化子控件的属性
        ageDriveLb = [[UILabel alloc]init];
        ageDriveLb.text = @"您的驾龄:";
        ageDriveLb.font = [UIFont systemFontOfSize:13];
        [self addSubview:ageDriveLb];
        
        ageDriverTF = [[UITextField alloc]init];
        ageDriverTF.layer.borderWidth = 1;
        ageDriverTF.layer.borderColor = blackLineColore.CGColor;
        [self addSubview:ageDriverTF];
        
        carMessLb = [[UILabel alloc]init];
        carMessLb.text = @"爱车信息:";
        carMessLb.font = [UIFont systemFontOfSize:13];
        [self addSubview:carMessLb];
        
        carbrandTF = [[UITextField alloc]init];
        carbrandTF.layer.borderWidth = 1;
        carbrandTF.layer.borderColor = blackLineColore.CGColor;
        [self addSubview:carbrandTF];
        
        carNameTF = [[UITextField alloc]init];
        carNameTF.layer.borderWidth = 1;
        carNameTF.layer.borderColor = blackLineColore.CGColor;
        [self addSubview:carNameTF];
        
        seatNumTF = [[UITextField alloc]init];
        seatNumTF.layer.borderWidth = 1;
        seatNumTF.layer.borderColor = blackLineColore.CGColor;
        [self addSubview:seatNumTF];
        
        zuoLb = [[UILabel alloc]init];
        zuoLb.text = @"座";
        zuoLb.font = [UIFont systemFontOfSize:13];
        [self addSubview:zuoLb];
        
        huodongLb = [[UILabel alloc]init];
        huodongLb.text = @"选择活动:";
        huodongLb.font = [UIFont systemFontOfSize:13];
        [self addSubview:huodongLb];
        
        huodongTF = [[UITextField alloc]init];
        huodongTF.layer.borderWidth = 1;
        huodongTF.layer.borderColor = blackLineColore.CGColor;
        [self addSubview:huodongTF];
        
        priceLb = [[UILabel alloc]init];
        priceLb.text = @"制定价格:";
        priceLb.font = [UIFont systemFontOfSize:13];
        [self addSubview:priceLb];
        
        priceTF = [[UITextField alloc]init];
        priceTF.layer.borderWidth = 1;
        priceTF.layer.borderColor = blackLineColore.CGColor;
        [self addSubview:priceTF];
        
        messageTV = [[UITextView alloc]init];
        messageTV.layer.borderWidth = 1;
        messageTV.layer.borderColor = blackLineColore.CGColor;
        [self addSubview:messageTV];
        
        UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Action:)];
        [self addGestureRecognizer:singleTap];
    }
    return self;
}

//在`layoutSubviews`方法中设置子控件的`frame`（在该方法中一定要调用`[super layoutSubviews]`方法）
- (void)layoutSubviews{
    [super layoutSubviews];
    
    //约束
    [ageDriveLb mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(self.mas_top).offset(15),
        make.left.mas_equalTo(self.mas_left).offset(50),
        make.width.mas_equalTo(60),
        make.height.mas_equalTo(15);
    }];
    
    [ageDriverTF mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(self.mas_top).offset(11),
        make.left.mas_equalTo(ageDriveLb.mas_right).offset(28),
        make.right.mas_equalTo(self.mas_right).offset(-50),
        make.height.mas_equalTo(30);
    }];
    
    [carMessLb mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(ageDriveLb.mas_bottom).offset(25),
        make.left.mas_equalTo(self.mas_left).offset(50),
        make.width.mas_equalTo(60),
        make.height.mas_equalTo(15);
    }];
    
    [carbrandTF mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(ageDriverTF.mas_bottom).offset(11),
        make.left.mas_equalTo(carMessLb.mas_right).offset(28),
        make.right.mas_equalTo(self.mas_right).offset(-50),
        make.height.mas_equalTo(30);
    }];
    
    [carNameTF mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(carbrandTF.mas_bottom).offset(8),
        make.left.mas_equalTo(carMessLb.mas_right).offset(28),
        make.right.mas_equalTo(self.mas_right).offset(-50),
        make.height.mas_equalTo(30);
    }];
    
    [seatNumTF mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(carNameTF.mas_bottom).offset(8),
        make.left.mas_equalTo(carMessLb.mas_right).offset(28),
        make.right.mas_equalTo(self.mas_right).offset(-90),
        make.height.mas_equalTo(30);
    }];
    
    [zuoLb mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(carNameTF.mas_bottom).offset(8),
        make.left.mas_equalTo(seatNumTF.mas_right).offset(10),
        make.right.mas_equalTo(self.mas_right).offset(-50),
        make.height.mas_equalTo(30);
    }];
    
    [huodongLb mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(seatNumTF.mas_bottom).offset(15),
        make.left.mas_equalTo(self.mas_left).offset(50),
        make.width.mas_equalTo(60),
        make.height.mas_equalTo(15);
    }];
    
    [huodongTF mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(seatNumTF.mas_bottom).offset(8),
        make.left.mas_equalTo(huodongLb.mas_right).offset(28),
        make.right.mas_equalTo(self.mas_right).offset(-50),
        make.height.mas_equalTo(30);
    }];
    
    [priceLb mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(huodongLb.mas_bottom).offset(30),
        make.left.mas_equalTo(self.mas_left).offset(50),
        make.width.mas_equalTo(60),
        make.height.mas_equalTo(15);
    }];
    
    [priceTF mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(huodongTF.mas_bottom).offset(15),
        make.left.mas_equalTo(priceLb.mas_right).offset(28),
        make.right.mas_equalTo(self.mas_right).offset(-50),
        make.height.mas_equalTo(30);
    }];
    
    [messageTV mas_makeConstraints:^(MASConstraintMaker *make){
        make.top.mas_equalTo(priceTF.mas_bottom).offset(15),
        make.left.mas_equalTo(self.mas_left).offset(50),
        make.right.mas_equalTo(self.mas_right).offset(-50),
        make.height.mas_equalTo(65);
    }];

}
//
- (void)Action:(id)sender{
    [self endEditing:YES];
}
@end
